package com.molyfun.parents.activity.organization.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.TextView;

import com.molyfun.parents.R;
import com.molyfun.parents.rest.bean.SignUpDetailResponse;
import com.molyfun.parents.rest.bean.SignUpFixParentInfoBean;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * Created by william(liuchao.hit@gmail.com).
 * Date:9/19/16.
 */
public class SigUpDetailEditParenteInfoAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>  {

    /**
     * TYPE_ADDED 已加入
     * TYPE_CHECK 审核中
     */
    private Context mContext;

    private Map<String, String> map = new HashMap<>();
    private List<SignUpDetailResponse.DataBean.ContactlistpageBean> contactlistpageList;
    private List<SignUpDetailResponse.DataBean.ContactlistpageBean> submitList = new ArrayList<>();
    private SigUpDetailParenteInfoViewHodler signUpListViewHolder;


    public SigUpDetailEditParenteInfoAdapter(Context mContext) {
        this.mContext = mContext;
    }

    public void refreshData(List<SignUpDetailResponse.DataBean.ContactlistpageBean> list) {
        this.contactlistpageList = list;
        notifyDataSetChanged();
    }

    public void clearAll() {
        if (contactlistpageList != null) {
            contactlistpageList.clear();
            notifyDataSetChanged();
        }
    }

    public Map<String, String> getMap() {
        return this.map;
    }


    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new SigUpDetailParenteInfoViewHodler(LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_sign_up_edie_detail_info, parent, false));
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
        signUpListViewHolder = (SigUpDetailParenteInfoViewHodler) holder;

        final SignUpDetailResponse.DataBean.ContactlistpageBean contactlistpageBean = contactlistpageList.get(position);
        signUpListViewHolder.mRelationship.setText(contactlistpageBean.getRelationship() + "信息");
        signUpListViewHolder.parente_info_name.setText(contactlistpageBean.getName());
        signUpListViewHolder.parente_info_identity.setText(contactlistpageBean.getCardid());
        signUpListViewHolder.parente_info_educate.setText(contactlistpageBean.getEducation());
        signUpListViewHolder.parente_info_occupation.setText(contactlistpageBean.getOccupation());
        signUpListViewHolder.parente_info_qq.setText(contactlistpageBean.getQq());
        signUpListViewHolder.parente_info_connect.setText(contactlistpageBean.getPhone());


        SignUpDetailResponse.DataBean.ContactlistpageBean bean = new SignUpDetailResponse.DataBean.ContactlistpageBean();
        bean.setRelationship(signUpListViewHolder.mRelationship.getText().toString().trim());
        bean.setName(signUpListViewHolder.parente_info_name.getText().toString().trim());
        bean.setCardid(signUpListViewHolder.parente_info_identity.getText().toString().trim());
        bean.setEducation(signUpListViewHolder.parente_info_educate.getText().toString().trim());
        bean.setOccupation(signUpListViewHolder.parente_info_occupation.getText().toString().trim());
        bean.setPhone(signUpListViewHolder.parente_info_connect.getText().toString().trim());
        bean.setQq(signUpListViewHolder.parente_info_qq.getText().toString().trim());
        submitList.add(bean);
        map.put("infoRelationship" + position, signUpListViewHolder.mRelationship.getText().toString().trim());
        map.put("infoName" + position, signUpListViewHolder.parente_info_name.getText().toString().trim());
        map.put("infoIdentity" + position, signUpListViewHolder.parente_info_identity.getText().toString().trim());
        map.put("infoEducate" + position, signUpListViewHolder.parente_info_educate.getText().toString().trim());
        map.put("infoOccupation" + position, signUpListViewHolder.parente_info_occupation.getText().toString().trim());
        map.put("infoQQ" + position, signUpListViewHolder.parente_info_qq.getText().toString().trim());
        map.put("infoConnect" + position, signUpListViewHolder.parente_info_connect.getText().toString().trim());


    }

    @Override
    public int getItemCount() {
        if (contactlistpageList == null) {
            return 0;
        } else {
            return contactlistpageList.size();
        }
    }


    class SigUpDetailParenteInfoViewHodler extends RecyclerView.ViewHolder {

        @InjectView(R.id.relationship)
        EditText mRelationship;
        @InjectView(R.id.parente_info_name)
        EditText parente_info_name;
        @InjectView(R.id.parente_info_identity)
        EditText parente_info_identity;
        @InjectView(R.id.parente_info_educate)
        EditText parente_info_educate;
        @InjectView(R.id.parente_info_occupation)
        EditText parente_info_occupation;
        @InjectView(R.id.parente_info_qq)
        EditText parente_info_qq;
        @InjectView(R.id.parente_info_connect)
        EditText parente_info_connect;

        public SigUpDetailParenteInfoViewHodler(View view) {
            super(view);
            ButterKnife.inject(this, view);
        }
    }
    public List<SignUpDetailResponse.DataBean.ContactlistpageBean> getSubmitInfoList() {
        return submitList;
    }

}
